from django.db import models
from django.contrib.auth.models import User

class KimlikBilgileri(models.Model):
    kullanici = models.OneToOneField(User)
    tcNo = models.CharField(max_length=11)
    yas = models.IntegerField()
    dogumTarihi = models.DateField()
    adres1 = models.CharField(max_length=30)
    adres2 = models.CharField(max_length=30)
    adres3 = models.CharField(max_length=30)
    websayfasi = models.CharField(max_length=30,null=True)

class Ders(models.Model):
    dersKodu = models.CharField(max_length=5)
    dersAdi = models.CharField(max_length=30)

class OgretimGorevlisi(models.Model):
    kimlikBilgisi = models.ForeignKey(KimlikBilgileri)
    unvan = models.CharField(max_length=20)
    bolum = models.ForeignKey('Bolum')

class Danisman(models.Model):
    ogretmenId = models.ForeignKey(OgretimGorevlisi)

class Universite(models.Model):
    universiteKodu = models.CharField(max_length=5)
    universiteAdi = models.CharField(max_length=50)
    rektor = models.ForeignKey(OgretimGorevlisi)

class Fakulte(models.Model):
    fakulteKodu = models.CharField(max_length=5)
    fakulteAdi = models.CharField(max_length=30)
    dekan = models.ForeignKey(OgretimGorevlisi)
    universite = models.ForeignKey(Universite)

class Bolum(models.Model):
    bolumKodu = models.CharField(max_length=5)
    bolumAdi = models.CharField(max_length=30)
    bolumBaskani = models.ForeignKey(OgretimGorevlisi,related_name="has")

class AcilanDers(models.Model):
    dersKodu = models.ForeignKey(Ders)
    ogretmen = models.ForeignKey(OgretimGorevlisi)
    bolum = models.ForeignKey(Bolum)
    dersSaati = models.IntegerField()
    dersKredisi = models.FloatField()
    sinif = models.IntegerField()
    donem = models.IntegerField()

class Ogrenci(models.Model):
    kimlikBilgisi = models.ForeignKey(KimlikBilgileri)
    sinif = models.IntegerField()
    danisman = models.ForeignKey(Danisman)
    dersKayit = models.ManyToManyField(AcilanDers,through='DersKayit')
    bolum = models.ManyToManyField(Bolum,through='BolumKayit')

class DersKayit(models.Model):
    ders = models.ForeignKey(AcilanDers)
    ogrenci = models.ForeignKey(Ogrenci)

class AldigiDersler(models.Model):
    ogrenciNo = models.ForeignKey(Ogrenci)
    dersKodu = models.ForeignKey(Ders)
    alinanYil = models.DateField()
    aldigiNot = models.CharField(max_length=2)
    devamsizlik = models.IntegerField()
    durum = models.IntegerField()

class BolumKayit(models.Model):
    ogrenciNo = models.ForeignKey(Ogrenci)
    bolum = models.ForeignKey(Bolum)
    kayitYili = models.DateField()

class OgrenciMezuniyet(models.Model):
    ogrenciNo = models.ForeignKey(Ogrenci)
    mezuniyet = models.CharField(max_length=30)
    yil = models.DateField()
    derece = models.FloatField()

class Transkript(models.Model):
    ogrenciNo = models.ForeignKey(Ogrenci)
    ders = models.ForeignKey(Ders)
    dersKredisi = models.FloatField()
    dersNotu = models.CharField(max_length=4)
